package com.hcxdi.app.droidbase.model;


import com.hcxdi.api.APIService;
import com.hcxdi.api.AuthService;
import com.hcxdi.api.HcxdiAPI;
import com.hcxdi.api.bean.auth.Auth;
import com.hcxdi.api.bean.auth.AuthReq;
import com.hcxdi.api.bean.base.Rsp;
import com.hcxdi.app.droidbase.contract.AuthContract;
import com.hcxdi.app.droidbase.util.RxUtils;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import rx.Observable;
import rx.Observer;

/**
 * TODO
 *
 * @author 成都青桔科技有限公司
 * @version 1.0
 * @changelog 16-11-9 初始化
 */
public class AuthModel implements AuthContract.Model {


    public <T  > T createAPISrv(Class<T> aClass) {
        String baseUrl="http://test.dadachefu.com/truck/";
        okhttp3.OkHttpClient.Builder mOkHttpBuilder = new OkHttpClient.Builder()
                .connectTimeout(5, TimeUnit.SECONDS)
                .readTimeout(5,TimeUnit.SECONDS)
                ;

        return HcxdiAPI.getInstance(mOkHttpBuilder.build(),baseUrl).createService(aClass);
    }

    @Override
    public Observable loadAuth(AuthReq req) {
        AuthService authService = createAPISrv(AuthService.class);
        return RxUtils.observable(authService.auth(req));
    }



}
